<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BStatus
 *
 * @author I062261
 */
class BStatus extends BEntityWithGroup {

    const Status_Object_Deleted = "status_object_deleted";
    const Status_Deleted_Id = 1;

    public $name = null;
    public $description = null;
    public $data = null;

    public static function find($context) {

        /*
          if ($context == self::Status_Object_Deleted) {
          $count = BMStatus::model()->count();
          if ($count == 0) {
          $status = new BStatus();
          $status->name = self::Status_Object_Deleted;
          $status->save();
          return $status;
          }
          $mStatus = BMStatus::model()->findByAttributes(array('name' => BStatus::Status_Object_Deleted));
          return new BStatus($mStatus->_id);
          //$status = new BStatus(); //this function is special
          } else if ($context != NULL) {
          return BStatus::find($context);
          }
         * 
         */
        if (is_string($context)) {
            $status = new BStatus();
            $status->name = $context;
            $context = $status;
        }
        
        $allStatus = self::findAll($context);
        
        if($allStatus != NULL)
            return reset($allStatus);            

        return FALSE;
    }

    public static function findAll($context) {
        $count = BRepositoryFactory::createRepository2()->getCount(new BStatus());
        if ($count == 0) {
            $status = new BStatus();
            $status->name = self::Status_Object_Deleted;
            $status->save();
            //return array($status->getId() => $status);
        }
        return parent::findAll($context);
    }

}

?>
